package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarEntryLog;
import com.ruoyi.system.service.ICarEntryLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆入场日志Controller
 * 
 * @author sunkai
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/system/entrylog")
public class CarEntryLogController extends BaseController
{
    @Autowired
    private ICarEntryLogService carEntryLogService;

    /**
     * 查询车辆入场日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarEntryLog carEntryLog)
    {
        startPage();
        List<Map<String,Object>> list = carEntryLogService.selectCarEntryLogListMap(carEntryLog);
        return getDataTable(list);
    }

    /**
     * 导出车辆入场日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:export')")
    @Log(title = "车辆入场日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarEntryLog carEntryLog)
    {
        List<CarEntryLog> list = carEntryLogService.selectCarEntryLogList(carEntryLog);
        ExcelUtil<CarEntryLog> util = new ExcelUtil<CarEntryLog>(CarEntryLog.class);
        util.exportExcel(response, list, "车辆入场日志数据");
    }

    /**
     * 获取车辆入场日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(carEntryLogService.selectCarEntryLogById(id));
    }

    /**
     * 新增车辆入场日志
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:add')")
    @Log(title = "车辆入场日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarEntryLog carEntryLog)
    {
        return toAjax(carEntryLogService.insertCarEntryLog(carEntryLog));
    }

    /**
     * 修改车辆入场日志
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:edit')")
    @Log(title = "车辆入场日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarEntryLog carEntryLog)
    {
        return toAjax(carEntryLogService.updateCarEntryLog(carEntryLog));
    }

    /**
     * 删除车辆入场日志
     */
    @PreAuthorize("@ss.hasPermi('system:entrylog:remove')")
    @Log(title = "车辆入场日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(carEntryLogService.deleteCarEntryLogByIds(ids));
    }

    /**
     * 查询车辆入场日志列表
     */
    @GetMapping("/countData")
    public List<Map<String,Object>> countData(CarEntryLog carEntryLog)
    {
        List<Map<String,Object>> list = carEntryLogService.selectCarEntryLogListGroup(carEntryLog);
        return list;
    }

}
